package com.zyb.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zyb.pojo.Grade;
import com.zyb.service.GradeService;
import com.zyb.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sms/gradeController")
public class GradeController {

    @Autowired
    private GradeService gradeService;

    //查询全部
    @GetMapping("/getGrades")
    public Result getGrades(){
        List<Grade> grades =gradeService.getGrades();
        return Result.ok(grades);
    }

    //分页 带条件查询
    @GetMapping("/getGrades/{pageNo}/{pageSize}")
    public Result getGrades(
            @PathVariable("pageNo") Integer pageNo,
            @PathVariable("pageSize") Integer pageSize,
            String gradeName) {
        //分页 带条件查询
        //Page<Grade> gradePage=new Page<>(pageNo,pageSize);
        IPage<Grade> iPage = gradeService.getGradePage(pageNo, pageSize, gradeName);
        return Result.ok(iPage);
    }

    //保存或修改
    @PostMapping("/saveOrUpdateGrade")
    public Result saveOrUpdateGrade(
            @RequestBody Grade grade) {
        // 接收参数
        // 调用服务层方法完成增减或者修改
        gradeService.saveOrUpdate(grade);
        return Result.ok();
    }

    //删除
    @DeleteMapping("/deleteGrade")
    public Result deleteGrade(@RequestBody List<Integer> ids) {
        gradeService.removeByIds(ids);
        return Result.ok();

    }
}
